package main

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

var db *sql.DB

func dbInit() (err error) {
	dsn := "root:xxxxx@tcp(127.0.0.1:3306)/cmdb2"
	db, err = sql.Open("mysql", dsn)
	if err != nil {
		fmt.Println("dsn错误:%v", err)
		return
	}
	err = db.Ping()
	if err != nil {
		return err
	}
	return nil

}

func main() {
	err := dbInit()
	if err != nil {
		fmt.Printf("init db failed,err:%v\n", err)
		return
	}
}
